<?php
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\UploadedFile;
use App\Util\SqlServerUtil;
use App\Util\Common;
use App\Services\OSS;
use App;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Query\Builder;
use Symfony\Component\Console\Helper\Table;
use PhpParser\Node\Const_;


class BaobiaoController extends Controller
{
	protected $response = [
			"Error" => 0,
			"Message" => "Success!",
			"Data" => []
	];
	
	protected $SqlServer = null;
	
	public function __construct(Request $request){
		$temp = SqlServerUtil::getModelDbs($request);
		if($temp){
			$this->SqlServer = $temp['SqlServer'];
			$this->DB = 'sqlsrv';
		}
	}
	
	/**
	 * 文件用途描述
	 * @date: 2020年1月17日 上午11:06:14
	 * @author: yy
	 */
	public function salaryList(Request $request)
	{
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =50;
		$pages = ($page-1)* $limit;
		$res =[];
		$fnameStr='';
		$timeStr='';
		if($request->has('fname') && $request->fname != '' && !empty($request->fname)){
			$fname =iconv('UTF-8', 'GBK', $request->fname);
			$fnameStr =" and s.fname like '%{$fname}%'";
		}
		if($request->has('ftime') && $request->ftime != '' && $request->ftime != 'null'){
			$timeStr =" and substring(convert(varchar,s.ftime ,120),0,8) = '{$request->ftime}'";
		}
		$sql ="SELECT TOP {$limit} s.* FROM yd_salary s where s.id not in (select TOP {$pages} s.id from yd_salary s
		where 1=1 {$fnameStr} {$timeStr} order by s.id desc)
		{$fnameStr} {$timeStr} order by s.id desc";
		$res = SqlServerUtil::exec($this->SqlServer,$sql);
		
		$countSql ="SELECT COUNT(1) AS total FROM yd_salary s where 1=1 {$fnameStr} {$timeStr}";
		$count = SqlServerUtil::exec($this->SqlServer, $countSql);
		
		$this->response['total'] = $count ? $count[0]['total']:0;
		$this->response['size'] = 1;
		$last_page =0;
		if($count && count($count)>0){
			$last_page = ceil($count[0]['total']/$limit);
			$this->response['size'] = $limit;
		}
		$this->response['result'] = $res;
		$this->response['cur_page'] =$page;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
	}
	
	/**
	 * 职工情况表zgqk
	 * @date: 2020年2月11日 下午4:56:45
	 * @author: yy
	 */
	public function zgqkList(Request $request)
	{
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =10;
		$pages = ($page-1)* $limit;
		$res =[];
		$fnameStr='';
		$fnumberStr='';
		$timeStr='';
		if($request->has('fname') && $request->fname != '' && !empty($request->fname)){
			$fname =iconv('UTF-8', 'GBK', $request->fname);
			$fnameStr =" and s.fname like '%{$fname}%'";
		}
		/* if($request->has('ftime') && $request->ftime != '' && $request->ftime != 'null'){
		 $timeStr =" and substring(convert(varchar,s.ftime ,120),0,8) = '{$request->ftime}'";
		 } */
		if($request->has('fnumber') && $request->fnumber != '' && !empty($request->fnumber)){
			$fnumber =iconv('UTF-8', 'GBK', $request->fnumber);
			$fnumberStr =" and s.fnumber like '%{$fnumber}%'";
		}
		
		$sql ="SELECT TOP {$limit} s.* FROM gz_gzzyqk  s where s.FItemID not in (select TOP {$pages} s.FItemID from gz_gzzyqk s
		where 1=1 {$fnameStr} {$fnumberStr}  order by s.Fnumber)
		{$fnameStr} {$fnumberStr} order by s.Fnumber ";
		$res = SqlServerUtil::exec($this->SqlServer,$sql);
		
		$countSql ="SELECT COUNT(1) AS total FROM gz_gzzyqk  s where 1=1 {$fnameStr} {$fnumberStr}";
		$count = SqlServerUtil::exec($this->SqlServer, $countSql);
		
		$this->response['total'] = $count ? $count[0]['total']:0;
		$this->response['size'] = 1;
		$last_page =0;
		if($count && count($count)>0){
			$last_page = ceil($count[0]['total']/$limit);
			$this->response['size'] = $limit;
		}
		
		$this->response['Data'] = $res;
		$this->response['cur_page'] =$page;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
	}
	
	/**
	 * 职工情况表 -- 新增
	 * @date: 2020年2月11日 下午5:08:42
	 * @author: yy
	 */
	public function zgqkAdd(Request $request)
	{
//   		dd($request->all(),$request->input('FItemID'));
		//职员代码 是否有值
		$param =$request->all();
		//FNumber ,FName
		if(!$request->input('FItemID')){
			$FItemID =1;
			$data = SqlServerUtil::exec($this->SqlServer, "select * from gz_gzzyqk where FNumber ='{$param['FNumber']}'",2);
			if($data) {return response()->json(Common::errorResponse(400,'职员代号已存在'));}
			$FItemIDStr = SqlServerUtil::exec($this->SqlServer, "select Max(fitemid) as rownum from gz_gzzyqk",2);
			if($FItemIDStr){
				$FItemID = $FItemIDStr['rownum'] +1;
			}
			$param = _unsetNull($param);
// 			$qkid = DB::table('gz_gzzyqk')->insert($param+['FItemID'=>$FItemID]);
			$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_gzzyqk',$param+['FItemID'=>$FItemID] );
			if($qkid){
				showMsg(200,'保存成功');
			}else{
				showMsg(400,'保存失败');
			}
		}else{
			$FItemID = $request->input('FItemID');
			unset($param['FItemID']);
			$param = _unsetNull($param);
			//$qkidupdate=DB::table('gz_gzzyqk')->where('FItemID',$FItemID)->update($param);
			$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,'gz_gzzyqk',$param,['FItemID'=>$FItemID]);
			if($qkidupdate){
				showMsg(200,'修改成功');
			}else{
				showMsg(400,'修改失败');
			}
			
		}
		
		
	}
	
	
	/**
	 * 职工情况表
	 * @date: 2020年2月11日 下午5:09:29
	 * @author: yy
	 */
	public function getqk(Request $request)
	{
		$data = SqlServerUtil::exec($this->SqlServer, "select FItemID,FNumber,FName from gz_gzzyqk ");
		
		$this->response['result'] = $data;
		return response()->json($this->response);
		
	}
	
	/**
	 * 职工情况表 --删除
	 * @date: 2020年2月11日 下午5:09:29
	 * @author: yy
	 */
	public function zgqkDel(Request $request)
	{
		$FItemID = $request ->get('FItemID');
		$qkid = SqlServerUtil::sqlexec($this->SqlServer,"DELETE gz_gzzyqk WHERE FItemID= '{$FItemID}'");
		if($qkid){
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
		
	}
	
	
	/**
	 * 职工考勤表zgkq
	 * @date: 2020年2月11日 下午4:56:45
	 * @author: yy
	 */
	public function zgkqList(Request $request)
	{
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =50;
		$pages = ($page-1)* $limit;
		$res =[];
		$fnameStr='';
		$fnumberStr='';
		$timeStr='';
		if($request->has('fname') && $request->fname != '' && !empty($request->fname)){
			//$fname =iconv('UTF-8', 'GBK', $request->fname);
			$fname =$request->fname;
			$fnameStr =" and t1.fname like '%{$fname}%'";
		}
		/* if($request->has('ftime') && $request->ftime != '' && $request->ftime != 'null'){
		 $timeStr =" and substring(convert(varchar,s.ftime ,120),0,8) = '{$request->ftime}'";
		 } */
		if($request->has('fnumber') && $request->fnumber != '' && !empty($request->fnumber)){
			//$fnumber =iconv('UTF-8', 'GBK', $request->fnumber);
			$fnumber=$request->fnumber;
			$fnumberStr =" and t1.fnumber like '%{$fnumber}%'";
		}
		
		//年度 期间 qjValue
		if($request->has('qjValue') && $request->qjValue != '' && !empty($request->qjValue) && $request->qjValue != 'null'){
			list($year,$mon) = explode('-',$request->qjValue);
			$timeStr .=" and u1.FYear = '{$year}'";
			$mon = intval($mon);
			$timeStr .=" and u1.FPeriod = '{$mon}'";
		}
		
		$sql ="(select
		u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FISZZ,u1.FYCQ,u1.FSCQ,u1.FSJ,u1.FBJ,u1.FCJ,u1.FHJ
		,u1.FGS,u1.FSAJ,u1.FNJ,u1.FPJ,u1.FLJ,u1.FRJH,u1.FRJY,u1.FFDJH,u1.FFDJY,u1.FKK,u1.FQQJ,u1.FQJKK,u1.FYB,u1.FZFGJ,u1.FSDF,u1.FTXBZ,u1.FHSBZ,u1.FTBBZ,u1.FDWYB
		from t_gzzykq u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
		$res=DB::table(DB::raw($sql))->orderBy('FYear','desc')->orderBy('FPeriod', 'desc')->orderBy('FNumber', 'asc')->paginate(50)->toArray();
		$result =[];
		if($res){
			foreach ($res['data'] as $k => $user) {
				$result[$k]= object_array($user);
			}
		}
		$arr =[
				'current_page'=>$res['current_page'],
				'data'=>$result,
				"from" => $res['from'],
				"last_page" => $res['last_page'],
				"next_page_url" => $res['next_page_url'],
				"path" =>$res['path'],
				"per_page" => $res['per_page'],
				"prev_page_url" => $res['prev_page_url'],
				"to" => $res['to'],
				"total" => $res['total'],
		];
		$this->response['result'] = $result;
		$this->response['cur_page'] =$page;
		$this->response['last_page'] = $res['last_page'];
		$this->response['size'] = $limit;
		$this->response['total'] = $res['total'];
		return response()->json($this->response);
	}
	
	/**
	 * 职工考勤添加
	 * @date: 2020年2月24日 上午9:15:57
	 * @author: yy
	 */
	public function zgkqAdd(Request $request)
	{
		$param =$request->get('pagram');
		//t_gzzykq
		
		$gg=[];
		$gg = SqlServerUtil::exec($this->SqlServer, "select * from gz_gzzyqk where FItemID ='{$param['FItemID']}'",2);
		$gg = ['FNumber' => $gg['FNumber'],'FName' => $gg['FName']];
		$param = array_merge($param,$gg);
		if($request->input('action') == 'add'){
			$data = SqlServerUtil::exec($this->SqlServer, "delete from t_gzzykq where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'",2);
			
			$qkid = DB::table('t_gzzykq')->insert($param);
			
			if($qkid){
				showMsg(200,'保存成功');
			}else{
				showMsg(400,'保存失败');
			}
		}else{
			//判断 查询是否添加过 FYear FPeriod  FItemID
			SqlServerUtil::exec($this->SqlServer, "delete from t_gzzykq where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
			$param = _unsetNull($param);
			//dd($param);
			$qkidupdate=DB::table('t_gzzykq')->insert($param);
			//$qkidupdate=DB::table('t_gzzyqk')->where('FItemID',$FItemID)->where('FYear',$param['FYear'])->where('FPeriod',$param['FPeriod'])->update($param);
			if($qkidupdate){
				showMsg(200,'修改成功');
			}else{
				showMsg(400,'修改失败');
			}
		}
		
	}
	/**
	 * 职工考勤表 --删除
	 * @date: 2020年2月11日 下午5:09:29
	 * @author: yy
	 */
	public function zgkqDel(Request $request)
	{
		$param = $request ->all();
		$qkid =SqlServerUtil::sqlexec($this->SqlServer, "delete from t_gzzykq where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
		if($qkid){
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
		
	}
	
	/**
	 * 各项补助 ----其他通用
	 * @date: 2020年2月24日 下午1:51:06
	 * @author: yy
	 */
	public function  zgbzList(Request $request)
	{
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =50;
		$pages = ($page-1)* $limit;
		$res =[];
		$fnameStr='';
		$fnumberStr='';
		$timeStr='';
		if($request->has('fname') && $request->fname != '' && !empty($request->fname)){
			//$fname =iconv('UTF-8', 'GBK', $request->fname);
			$fname =$request->fname;
			$fnameStr =" and t1.fname like '%{$fname}%'";
		}
		/* if($request->has('ftime') && $request->ftime != '' && $request->ftime != 'null'){
		 $timeStr =" and substring(convert(varchar,s.ftime ,120),0,8) = '{$request->ftime}'";
		 } */
		if($request->has('fnumber') && $request->fnumber != '' && !empty($request->fnumber)){
			//$fnumber =iconv('UTF-8', 'GBK', $request->fnumber);
			$fnumber=$request->fnumber;
			$fnumberStr =" and t1.fnumber like '%{$fnumber}%'";
		}
		
		//年度 期间
		if($request->has('qjValue') && $request->qjValue != '' && !empty($request->qjValue) && $request->qjValue != 'null'){
			list($year,$mon) = explode('-',$request->qjValue);
			$timeStr .=" and u1.FYear = '{$year}'";
			$mon = intval($mon);
			$timeStr .=" and u1.FPeriod = '{$mon}'";
		}
		
		switch ($request->action){
			//考勤
			case "zykq":
				echo "i is apple";
				break;
				//职员补助
			case "zybz":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FZFBT,u1.FTXBT,u1.FHSBT,u1.FTBBT,u1.FGLGZ,u1.FCYBT,u1.FJJGZ,u1.FNote
				from t_gzzybz u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员伙食
			case "zyhs":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FHSF
				from t_gzhshz u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员水电
			case "zysd":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FSDF
				from t_gzsdkk u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员出车补助表
			case "zycc":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FCCBZ
				from t_gzccbz u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1  {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员回收桶
			case "zyhst":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FTT,u1.FYHKSXJE,u1.FKYFGZ,u1.FQTKK,u1.FXJZKK,u1.FKHJE,u1.FQty,u1.FQtyZS
				from t_gzhsthz u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员考核系数
			case "zykh":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FKHXS,u1.FKHJE
				from t_gzkhxs u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1  {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员各项扣款
			case "zygxkk":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FKGY,u1.FFPK,u1.FKJK,u1.FLYK,u1.FQTKK,u1.FZKBL,u1.FKYFGZ
				from t_gzzygxkk u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
				//职员社保
			case "zysb":
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FYLBX,u1.FYB,u1.FZFGJ
				from t_gzzysbhz u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
			///////延期扣款
			case "zyyq":	
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,
				u1.FCustomer,u1.FZKBL,u1.FYDSJ,u1.FHKJE,u1.id,u1.FCQSJ,u1.FZKBLJE
				from t_gzyqkk u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
			case 'xjzk':
				$sql ="(select
				u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,
				u1.FCustomer,u1.FXJZK,u1.id
				from t_gzxjzk u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
				where 1=1 {$fnameStr} {$fnumberStr} {$timeStr}) as cc";
				break;
		}
		//    	  echo $sql;die;
		$res=DB::table(DB::raw($sql))->orderBy('FYear','desc')->orderBy('FPeriod', 'desc')->orderBy('FNumber', 'asc')->paginate(50)->toArray();
		$result =[];
		if($res){
			foreach ($res['data'] as $k => $user) {
				$result[$k]= object_array($user);
			}
		}
		$arr =[
				'current_page'=>$res['current_page'],
				'data'=>$result,
				"from" => $res['from'],
				"last_page" => $res['last_page'],
				"next_page_url" => $res['next_page_url'],
				"path" =>$res['path'],
				"per_page" => $res['per_page'],
				"prev_page_url" => $res['prev_page_url'],
				"to" => $res['to'],
				"total" => $res['total'],
		];
		$this->response['result'] = $result;
		$this->response['last_page'] = $res['last_page'];
		$this->response['size'] = $limit;
		$this->response['total'] = $res['total'];
		return response()->json($this->response);
	}
	
	/**
	 * 各项补助 新增
	 * @date: 2020年2月24日 下午2:50:18
	 * @author: yy
	 */
	public function zgbzAdd(Request $request)
	{
		$param =$request->get('pagram');
		//t_gzzykq
		if($request->input('action') == 'add'){
			$data = SqlServerUtil::exec($this->SqlServer, "delete from t_gzzybz where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'",2);
			
			$qkid = DB::table('t_gzzybz')->insert($param);
			
			if($qkid){
				showMsg(200,'保存成功');
			}else{
				showMsg(400,'保存失败');
			}
		}else{
			//判断 查询是否添加过 FYear FPeriod  FItemID
			SqlServerUtil::exec($this->SqlServer, "delete from t_gzzybz where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
			$param = _unsetNull($param);
			//dd($param);
			$qkidupdate=DB::table('t_gzzybz')->insert($param);
			//$qkidupdate=DB::table('t_gzzyqk')->where('FItemID',$FItemID)->where('FYear',$param['FYear'])->where('FPeriod',$param['FPeriod'])->update($param);
			if($qkidupdate){
				showMsg(200,'修改成功');
			}else{
				showMsg(400,'修改失败');
			}
		}
		
	}
	/**
	 * 各项补助 --删除
	 * @date: 2020年2月11日 下午5:09:29
	 * @author: yy
	 */
	public function zgbzDel(Request $request)
	{
		$param = $request ->all();
		$qkid =SqlServerUtil::sqlexec($this->SqlServer, "delete from t_gzzybz where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
		if($qkid){
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
		
	}
	
	/**
	 * 职员伙食汇总 新增  ---其他通用
	 * @date: 2020年2月24日 下午4:19:26
	 * @author: yy
	 */
	public function zghsAdd(Request $request)
	{
		switch ($request ->get('type'))
		{
			case 'zyhs':
				$db = 't_gzhshz';
				break;
			case 'zysd':
				$db = 't_gzsdkk';
				break;
				//职员出车补助表
			case 'zycc':
				$db = 't_gzccbz';
				break;
				//职员回收桶
			case 'zyhst':
				$db = 't_gzhsthz';
				break;
				//职员考核系数
			case 'zykh':
				$db = 't_gzkhxs';
				break;
				//职员各项扣款
			case 'zygxkk':
				$db = 't_gzzygxkk';
				break;
				//职员社保
			case 'zysb':
				$db = 't_gzzysbhz';
				break;
			//延期扣款
			case 'zyyq':
				$db = 't_gzyqkk';
				break;
			case 'xjzk':
				$db = 't_gzxjzk';
				break;
			default:
				$db = 't_gzhshz';
		}
		$param =$request->get('pagram');
		$gg=[];
		$gg = SqlServerUtil::exec($this->SqlServer, "select * from t_gzzyqk where FItemID ='{$param['FItemID']}'",2);
		$gg = ['FNumber' => $gg['FNumber'],'FName' => $gg['FName']];
		$param = array_merge($param,$gg);
		//t_gzzykq
		if($request->input('action') == 'add'){
			if($request ->get('type') == 'zyyq' || $request ->get('type') == 'xjzk'){
				$qkid = DB::table($db)->insert($param);
				if($qkid){
					showMsg(200,'保存成功');
				}else{
					showMsg(400,'保存失败');
				}
			}
			$data = SqlServerUtil::exec($this->SqlServer, "delete from {$db} where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'",2);
			$qkid = DB::table($db)->insert($param);
			
			if($qkid){
				showMsg(200,'保存成功');
			}else{
				showMsg(400,'保存失败');
			}
		}else{
			if($request ->get('type') == 'zyyq' || $request ->get('type') == 'xjzk'){
				//SqlServerUtil::exec($this->SqlServer, "delete from {$db} where id ='{$param['id']}' and FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
				$param = _unsetNull($param);
				$id=$param['id'];
				unset($param['id']);
				$qkidupdate=DB::table($db)->where('id',$id)->update($param);
				//$qkidupdate=DB::table('t_gzzyqk')->where('FItemID',$FItemID)->where('FYear',$param['FYear'])->where('FPeriod',$param['FPeriod'])->update($param);
				if($qkidupdate){
					showMsg(200,'修改成功');
				}else{
					showMsg(400,'修改失败');
				}
				
			}
			
			//判断 查询是否添加过 FYear FPeriod  FItemID
			SqlServerUtil::exec($this->SqlServer, "delete from {$db} where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
			$param = _unsetNull($param);
			$qkidupdate=DB::table($db)->insert($param);
			//$qkidupdate=DB::table('t_gzzyqk')->where('FItemID',$FItemID)->where('FYear',$param['FYear'])->where('FPeriod',$param['FPeriod'])->update($param);
			if($qkidupdate){
				showMsg(200,'修改成功');
			}else{
				showMsg(400,'修改失败');
			}
		}
	}
	/**
	 *职员伙食汇总  删除 ---其他通用
	 * @date: 2020年2月11日 下午5:09:29
	 * @author: yy
	 */
	public function zghsDel(Request $request)
	{
		switch ($request ->get('type'))
		{
			case 'zyhs':
				$db = 't_gzhshz';
				break;
			case 'zysd':
				$db = 't_gzsdkk';
				break;
				//职员出车补助表
			case 'zycc':
				$db = 't_gzccbz';
				break;
				//职员回收桶
			case 'zyhst':
				$db = 't_gzhsthz';
				break;
				//职员考核系数
			case 'zykh':
				$db = 't_gzkhxs';
				break;
				//职员各项扣款
			case 'zygxkk':
				$db = 't_gzzygxkk';
				break;
				//职员社保
			case 'zysb':
				$db = 't_gzzysbhz';
				break;
			case 'zyyq':
				$db = 't_gzyqkk';
				break;
			case 'xjzk':
				$db = 't_gzxjzk';
				break;
				
			default:
				$db = 't_gzhshz';
		}
		if($request ->get('type') == 'zyyq' || $request ->get('type') == 'xjzk'){
			$param = $request ->all();
			$qkid =SqlServerUtil::sqlexec($this->SqlServer, "delete from  {$db}  where id ='{$param['id']}' and FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
			if($qkid){
				showMsg(200,'删除成功');
			}else{
				showMsg(400,'删除失败');
			}
			
		}else {
			$param = $request ->all();
			$qkid =SqlServerUtil::sqlexec($this->SqlServer, "delete from  {$db}  where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
			if($qkid){
				showMsg(200,'删除成功');
			}else{
				showMsg(400,'删除失败');
			}
		}
	}
	
	/**
	* 生成工资汇总
	* @date: 2020年2月28日 下午5:18:06
	* @author: yy
	*/
	public function scgzList(Request $request)
	{
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =50;
		$pages = ($page-1)* $limit;
		$res =[];
		$fnameStr='';
		$fnumberStr='';
		$timeStr='';
		if($request->has('fname') && $request->fname != '' && !empty($request->fname)){
			//$fname =iconv('UTF-8', 'GBK', $request->fname);
			$fname =$request->fname;
			$fnameStr =" and t1.fname like '%{$fname}%'";
		}
		/* if($request->has('ftime') && $request->ftime != '' && $request->ftime != 'null'){
		 $timeStr =" and substring(convert(varchar,s.ftime ,120),0,8) = '{$request->ftime}'";
		 } */
		if($request->has('fnumber') && $request->fnumber != '' && !empty($request->fnumber)){
			//$fnumber =iconv('UTF-8', 'GBK', $request->fnumber);
			$fnumber=$request->fnumber;
			$fnumberStr =" and t1.fnumber like '%{$fnumber}%'";
		}
		//年度 期间
		if($request->has('qjValue') && $request->qjValue != '' && !empty($request->qjValue) && $request->qjValue != 'null'){
			list($year,$mon) = explode('-',$request->qjValue);
			$timeStr .=" and u1.FYear = '{$year}'";
			$mon = intval($mon);
			$timeStr .=" and u1.FPeriod = '{$mon}'";
		}
		$sort='asc';
		$sortDesc='desc';
		if($request->action == 'jiazai'){
			$sql ="(select * from t_gzzyqk where 1=1  {$fnameStr} {$fnumberStr} {$timeStr} ) as cc";
			$orderstr1 = 'FItemID';
			$orderstr2 = 'FNumber';
			$limit =10000;
			$res=DB::table(DB::raw($sql))->orderBy($orderstr1,$sort)->orderBy($orderstr2, $sort)->paginate(2000)->toArray();
		}else{
			$sql ="(select
			u1.FYear,u1.FPeriod,u1.FItemID,t1.FNumber,u1.FZFGJ,u1.FJBPS,u1.FJBZM,u1.FJBFD,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,u1.FSCQ,u1.FDJGZ,u1.FRGZ,u1.FKHXS,u1.FJBGZ,u1.FGWGZ,u1.FKHGZ,u1.FJaBGZ,u1.FGZXJ,u1.FZFBZ,u1.FGLGZ,u1.FCCBZ,u1.FTBBZ,u1.FHSBZ,u1.FCYBZ,u1.FTXBZ,u1.FTT,u1.FJJGZ,u1.FRCJB,u1.FQGJ,u1.FYFHJ,u1.FYLBX,u1.FYB
			,u1.FQQKK,u1.FJSGZ,u1.FDKS,u1.FCF,u1.FKGY,u1.FFPK,u1.FKJK,u1.FKSDF,u1.FLYK,u1.FKKHJ,u1.FSFHJ,u1.FFFFS,u1.FQTKK,u1.FZHSFHJ,u1.FZKBLJE,u1.FKK,u1.FYHKSXJE,u1.STJE,u1.FKYFGZ
			,u1.FXJZKK ,u1.FSDF ,u1.FQJKK ,u1.FQQJ,u1.FRemark,u1.FGRTCFY,u1.FDWYB,u1.FKDHF
			from t_gzlb u1 inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
			where 1=1  {$fnameStr} {$fnumberStr} {$timeStr} ) as cc";
			$orderstr1 = 'FYear';
			$orderstr2 = 'FPeriod';
			$orderstr3 = 'FNumber';
			$res=DB::table(DB::raw($sql))->orderBy($orderstr1,$sortDesc)->orderBy($orderstr2, $sortDesc)->orderBy($orderstr3,$sort)->paginate(2000)->toArray();
		}
	
		
		$result =[];
		if($res){
			foreach ($res['data'] as $k => $user) {
				$result[$k]= object_array($user);
			}
		}
		$arr =[
				'current_page'=>$res['current_page'],
				'data'=>$result,
				"from" => $res['from'],
				"last_page" => $res['last_page'],
				"next_page_url" => $res['next_page_url'],
				"path" =>$res['path'],
				"per_page" => $res['per_page'],
				"prev_page_url" => $res['prev_page_url'],
				"to" => $res['to'],
				"total" => $res['total'],
		];
		$this->response['result'] = $result;
		$this->response['last_page'] = $res['last_page'];
		$this->response['size'] = $limit;
		$this->response['total'] = $res['total'];
		return response()->json($this->response);
		
	}
	
	/**
	* 工资计算
	* @date: 2020年3月2日 下午4:48:32
	* @author: yy
	*/
	public function jisuanList(Request $request)
	{
		//dd($request->all());	
		$qijian = $request->get('qjValue');
		$data = $request->get('rows');
		$kqData =[];
		$limit=10000;
		list($FYear,$FPeriod) = explode('-',$qijian);
		//判断该用户是否有考勤
		if($data){
			$FItemIDs = join(array_column($data, 'FItemID'),',');
			$FNameStr = join(array_column($data, 'FName'),',');
			/* $sql = "select
		u1.FYear,u1.FPeriod,u1.FItemID,u1.FYCQ,u1.FSCQ,u1.FSJ,u1.FBJ,u1.FCJ,u1.FHJ,u1.FGS,u1.FSAJ,u1.FNJ,u1.FPJ,u1.FLJ,u1.FRJH,u1.FRJY,u1.FFDJH,u1.FFDJY,u1.FKK,u1.FISZZ,u1.FQQJ
		,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,t1.FDJGZ,t1.FYWQGJ,t1.FFFFS,t1.FRCJBFlag,t1.FRCQTS
		,isnull(bz.FZFBT,0) as FZFBZ,isnull(bz.FTXBT,0) as FTXBZ,isnull(bz.FHSBT,0) as FHSBZ,isnull(bz.FTBBT,0) as FTBBZ,isnull(bz.FGLGZ,0) as FGLGZ,isnull(bz.FCYBT,0) as FCYBZ,isnull(bz.FJJGZ,0) as FJJGZ
		,isnull(hs.FHSF,0) as FCF,isnull(sd.FSDF,0) as FKSDF,isnull(cc.FCCBZ,0) as FCCBZ,isnull(hst.FTT,0) as FTT, isnull(hst.FYHKSXJE,0) as FYHKSXJE ,isnull(kh.FKHXS,0) as FKHXS,isnull(kh.FKHJE,0) as FKHGZ
		,isnull(gx.FKGY,0) as FKGY,isnull(gx.FFPK,0) as FFPK,isnull(gx.FKJK,0) as FKJK,isnull(gx.FLYK,0) as FLYK,isnull(gx.FQTKK,0) as FQTKK,isnull(gx.FZKBL,0) as FZKBL,isnull(gx.FKYFGZ,0) as FKYFGZ
		,isnull(sb.FYLBX,0) as FYLBX,isnull(sb.FYB,0) as FYB,isnull(sb.FZFGJ,0) as FZFGJ
	    from t_gzzykq u1 
		inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid  
		left join  t_gzzybz bz ON bz.FItemID =u1.FItemID and bz.fyear='{$FYear}' and bz.fperiod='{$FPeriod}' 
		left join  t_gzhshz hs ON hs.FItemID =u1.FItemID and hs.fyear='{$FYear}' and hs.fperiod='{$FPeriod}' 
		left join  t_gzsdkk sd ON sd.FItemID =u1.FItemID and sd.fyear='{$FYear}' and sd.fperiod='{$FPeriod}' 
		left join  t_gzccbz cc ON cc.FItemID =u1.FItemID and cc.fyear='{$FYear}' and cc.fperiod='{$FPeriod}' 
		left join  t_gzhsthz hst ON hst.FItemID =u1.FItemID and hst.fyear='{$FYear}' and hst.fperiod='{$FPeriod}' 
		left join  t_gzkhxs kh ON kh.FItemID =u1.FItemID and kh.fyear='{$FYear}' and kh.fperiod='{$FPeriod}' 
		left join  t_gzzygxkk gx ON gx.FItemID =u1.FItemID and gx.fyear='{$FYear}' and gx.fperiod='{$FPeriod}' 
		left join  t_gzzysbhz sb ON sb.FItemID =u1.FItemID and sb.fyear='{$FYear}' and sb.fperiod='{$FPeriod}'  */
			
			$sql = "select
			u1.FYear,u1.FPeriod,u1.FItemID,isnull(u1.FYCQ,0) as FYCQ,isnull(u1.FSCQ,0) as FSCQ,isnull(u1.FQQJ,0) as FQQJ,isnull(u1.FQJKK,0) as FQJKK,isnull(u1.FYB,0) as FYB,isnull(u1.FZFGJ,0) as FZFGJ,isnull(u1.FSDF,0) as FSDF
			,isnull(u1.FKK,0) as FKK,isnull(u1.FTXBZ,0) as FTXBZ,isnull(u1.FHSBZ,0) as FHSBZ,isnull(u1.FTBBZ,0) as FTBBZ,isnull(u1.FDWYB,0) as FDWYB
			,t1.FNumber,t1.FBXDH,t1.FGRZH,t1.FName,t1.FBM,t1.FZW,t1.FGW,t1.FDJGZ,t1.FFFFS
			,isnull(hst.FYHKSXJE,0) as FYHKSXJE,isnull(hst.FTT,0) as FTT,isnull(hst.FKYFGZ,0) as FKYFGZ,isnull(hst.FQTKK,0) as FQTKK,isnull(hst.FKHJE,0) as FKHJ
			,isnull(hst.FQty,0) as FQty,isnull(hst.FQtyZS,0) as FQtyZS,isnull(hst.FGRTCFY,0) as FGRTCFY,isnull(hst.FKDHF,0) as FKDHF
			,isnull(yq.FZKBL,0) FZKBL,isnull(xj.FXJZKK, 0) FXJZKK,t2.FRemark
			from t_gzzykq u1 
			inner join t_gzzyqk t1 on u1.fitemid=t1.fitemid
			left join  t_gzhsthz hst ON hst.FItemID =u1.FItemID and hst.fyear='{$FYear}' and hst.fperiod='{$FPeriod}' 
			left join  (select sum(isnull(yqkk.FZKBL,0)) as FZKBL,max(fyear) fyear,max(fperiod) fperiod,max(FItemID) FItemID 
			from t_gzyqkk yqkk where yqkk.fyear='{$FYear}' and yqkk.fperiod='{$FPeriod}' GROUP BY yqkk.FItemID) as yq on yq.FItemID = u1.FItemID AND yq.fyear = '{$FYear}' AND yq.fperiod = '{$FPeriod}'   
			
			LEFT JOIN (SELECT SUM (isnull(xjzk.FXJZK, 0)) AS FXJZKK,MAX (fyear) fyear,MAX (fperiod) fperiod,MAX (FItemID) FItemID
			FROM t_gzxjzk xjzk WHERE xjzk.fyear = '{$FYear}' AND xjzk.fperiod = '{$FPeriod}' GROUP BY xjzk.FItemID) AS xj ON xj.FItemID = u1.FItemID AND xj.fyear = '{$FYear}' AND xj.fperiod = '{$FPeriod}'

			left join  (SELECT FItemID,fyear,fperiod,(select  FCustomer + ':' +  CAST (CONVERT(float, FZKBL) AS VARCHAR(8))+'%' from t_gzyqkk a where a.FItemID = b.FItemID  for xml path('')) as FRemark		
			FROM t_gzyqkk b group by FItemID,fperiod,fyear) as t2 on t2.FItemID = u1.FItemID AND t2.fyear = '{$FYear}' AND t2.fperiod = '{$FPeriod}'
			where u1.FItemID in ($FItemIDs)  and u1.FYear = '{$FYear}' and u1.FPeriod ='{$FPeriod}'";
			//echo $sql;die;
			//left join  t_gzyqkk yq ON yq.FItemID =yq.FItemID and yq.fyear='{$FYear}' and yq.fperiod='{$FPeriod}' 
			$kqData = SqlServerUtil::exec($this->SqlServer, $sql);
			
			if($kqData){
				$tempKq = $data;
				foreach ($tempKq as $k =>$v)
				{
					foreach ($kqData as $k1 =>$v1){
						if($v['FItemID'] == $v1['FItemID']) {
							unset($tempKq[$k]);
						}
					}
				}
				if($tempKq){
					$FNameStr = join(array_column($tempKq, 'FName'),',');
					showMsg(400,"职员考勤记录为空(职员姓名：{$FNameStr})");
				}
			}else{
				showMsg(400,"职员考勤记录为空(职员姓名：{$FNameStr})");
			}
			//$kqData
			foreach ($kqData as $kk =>&$vv)
			{
				if(empty($vv['FYCQ'])){
					showMsg(400,"职员考情记录为空(职员姓名：{$vv['FName']})");
				}
				//基本工资
				$vv['FJBGZ'] = $vv['FDJGZ'];
				//考核工资
				/////#################/////---删掉
				//计提金额 STJE-- 浮动工资 , FYHKSXJE 已回款销售金额
				$vv['STJE'] =  getTiCheng($vv['FGW'], $vv['FYHKSXJE'],$vv['FQty'],$vv['FQtyZS']);
				/////#################/////---删掉
				//最终基本工资
				$gbgz =0;
				$gbgz = $vv['FJBGZ'] + $vv['STJE'];
				$vv['FJaBGZ'] =0;
				//提成工资FKHJE 
				$vv['FKHGZ'] = getkaohe($vv['FGW'], $vv['FKHJ']);
				//FGRTCFY --个人提成 + $vv['FGRTCFY']
				//工资小计 = 基本工资FJBGZ + 计提金额 STJE +  考核工资FKHGZ(提成工资)
				if($vv['FGW'] == "部门主管"){
					$vv['FGZXJ'] = $vv['FJBGZ']  + $vv['FKHGZ'] + $vv['FGRTCFY'];
				}else{
					$vv['FGZXJ'] = $vv['FJBGZ'] +  $vv['STJE'] + $vv['FKHGZ']+$vv['FGRTCFY'];
				}
				//dblQJ
				//$dblQJ = $vv['FSJ']+ $vv['FBJ'] +$vv['FCJ']+$vv['FHJ']+ $vv['FGS'] +$vv['FSAJ']+$vv['FNJ'];
			    
				/////#################/////---删掉
				//$vv['FRCJB'] 
				//$vv['FRCJB'] =0;
				//$vv['FQGJ'] = 0;
				/////#################/////
				
				//缺勤扣款FQQKK ---FSJ事假  ，日工资 FRGZ，病假 FBJ
			    //$vv['FQQKK'] = ($vv['FRGZ'] * $vv['FSJ'])/8 + (($vv['FRGZ'] * $vv['FBJ'])/8)*0.4;
				//请假：基本工资/天数*请假天数 
// 				echo '<pre>';
// 				echo $vv['FName'].(floatval($gbgz)/@floatval($vv['FYCQ']))*(floatval($vv['FYCQ']) - floatval($vv['FSCQ']));
// 				echo $vv['FName'].'-'.$gbgz.'-'.$vv['FYCQ'].'-'. $vv['FSCQ'];
				if($vv['FYCQ'] == 0){
					$vv['FQJKK']=0;
				}else{
					$vv['FQJKK']= ($gbgz/$vv['FYCQ'])*($vv['FYCQ'] - $vv['FSCQ']);
				}
			    //应发合计 = 工资小计FGZXJ + 住房补助FZFBZ + 工龄工资FGLGZ + 出车餐补FCCBZ +特别补助 FTBBZ +伙食补助FHSBZ + 车油补助FCYBZ + 通讯补助FTXBZ + 综合费用 FTT 部门奖金 + 计件工资FJJGZ +加班工资FRCJB + 全勤奖 FQGJ +全勤奖FQQJ
				$vv['FYFHJ'] = $vv['FGZXJ'] +$vv['FTBBZ']+$vv['FHSBZ'] +$vv['FTXBZ'] +$vv['FTT']+$vv['FQQJ']+$vv['FDWYB'] ;
			    //计税工资
			    //$FJSGZ= $vv['FYFHJ'] - $vv['FYLBX'] - $vv['FYB'] - $vv['FZFGJ'] - $vv['FQQKK'];
			    //$vv['FJSGZ'] = $FJSGZ;
			    //代扣税---个人所得税计算函数
			    /////#################/////---删掉
			   // $dblTmp = $FJSGZ;
			    //$vv['FDKS'] = Sui2012($dblTmp, 3500) ;
			    /////#################/////
			   // $vv['FDKS'] =0;
				//FDWYB 
			    //扣款合计 = 养老保险FYLBX + 医保FYB + 公积金FZFGJ + 缺勤扣款FQQKK + 代扣税FDKS + 餐费FCF + 扣工衣FKGY + 
			    //罚赔款FFPK现金暂扣款 + 扣借款FKJK请假扣款 + FSDF扣水电费FKSDF + 旅游款FLYK + 其他扣款FQTKK + 迟到扣款FKK + 请假扣款 FQJKK
				$vv['FKKHJ'] =  $vv['FYB']+ $vv['FZFGJ']+$vv['FQJKK']+ $vv['FKK'] + $vv['FSDF']+  $vv['FKDHF'] +$vv['FDWYB']  ; 
			    //实发合计
			    $vv['FSFHJ'] = $vv['FYFHJ'] - $vv['FKKHJ'];
			    //最后实发合计 =实发合计 - 暂扣比例金额  ，FXJZKK--现金暂扣款 - FKYFGZ已发工资
			    //其他扣款 改为 合伙人借款-- $vv['FQTKK'] 有 合伙人为1，没有为0
			    if($vv['FQTKK']>0){
			    	$vv['FQTKK'] = ($vv['FYFHJ'])*0.2;
			    }else{
			    	$vv['FQTKK'] =0;
			    }
			    $vv['FZKBLJE'] = $vv['FSFHJ']*$vv['FZKBL']/100;
			    $vv['FZHSFHJ'] = $vv['FSFHJ'] - $vv['FZKBLJE'] - $vv['FXJZKK'] -$vv['FKYFGZ'] - $vv['FQTKK'];
			}
 			//dd($kqData);
		}
		$this->response['result'] = $kqData;
		$this->response['total'] = count($kqData)?count($kqData):0;
		$this->response['size'] = 1;
		if(count($kqData)>0){
			$last_page = ceil(count($kqData)/$limit);
			$this->response['size'] = $limit;
		}
		$this->response['cur_page'] =$page;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
	}
	
	/**
	* 生成工资汇总 删除
	* @date: 2020年2月28日 下午5:29:21
	* @author: yy
	*/
	public function scgzDel(Request $request)
	{
		$db ='t_gzlb';
		$param = $request ->all();
		$qkid =SqlServerUtil::sqlexec($this->SqlServer, "delete from  {$db}  where FItemID ='{$param['FItemID']}' and FYear  ='{$param['FYear']}' and FPeriod ='{$param['FPeriod']}'");
		if($qkid){
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
	}
	
	/**
	* 保存
	* @date: 2020年3月4日 上午8:56:24
	* @author: yy
	*/
	public function scgzSave(Request $request)
	{
		$param = $request ->all();
		if(empty($param)){
			showMsg(400,'保存数据不能为空');
		}
		$data=[];
		$arr=[];
		foreach ($param as $k =>$v)
		{
			
			$arr[$k]= [
					'FYear'=>$v['FYear'],
					'FPeriod'=>$v['FPeriod'],
					'FItemID'=>$v['FItemID'],
					'FSFHJ'=>floatval($v['FSFHJ']), //实发合计 
					'FRemark'=>emptyStrZH($v['FRemark']),  //逾期备注
					];
					
			$data[$k]= [
					'FYear'=>$v['FYear'],
					'FPeriod'=>$v['FPeriod'],
					'FItemID'=>$v['FItemID'],
					
					'FDJGZ'=>floatval($v['FJBGZ']),  
					'FRGZ'=>0,
					'FKHXS'=>0,
					'FJBGZ'=>floatval($v['FJBGZ']),  //基本工资
					'FKHGZ'=>floatval($v['FKHGZ']),  //工资提成
					
					'FGZXJ'=>floatval($v['FGZXJ']), //工资小计 
					'FZFBZ'=>0,
					'FGLGZ'=>0,
					'FCCBZ'=>0,
					'FTBBZ'=>$v['FTBBZ'],
					
					'FHSBZ'=>$v['FHSBZ'],
					'FCYBZ'=>0,
					'FTXBZ'=>$v['FTXBZ'],
					'FTT'=>floatval($v['FTT']), //综合费用
					'FJJGZ'=>0, //计件工资删
					
					'FRCJB'=>0,
					'FQGJ'=>0,
					'FYFHJ'=>floatval($v['FYFHJ']), //应发合计
					'FYLBX'=>0,
					'FYB'=>$v['FYB'],
					
					'FQQKK'=>0,
					'FJSGZ'=>0, //计税工资 删
					'FDKS'=>0,
					'FCF'=>0,
					'FKGY'=>0,
					
					'FFPK'=>0,
					'FKJK'=>0,
					'FKSDF'=>0,
					'FLYK'=>0,
					'FKKHJ'=>floatval($v['FKKHJ']), //扣款合计
					
					'FSFHJ'=>floatval($v['FSFHJ']), //实发合计 
					'FFFFS'=>emptyStr($v['FFFFS']),
					'FSCQ'=>floatval($v['FSCQ']), //实际出勤
					'FQTKK'=>floatval($v['FQTKK']), //其它扣款
					'FJBPS'=>0,
					
					'FJBZM'=>0,
					'FJBFD'=>0,
					'FZFGJ'=>floatval($v['FZFGJ']),  //住房公积金
					'FZKBLJE'=>floatval($v['FZKBLJE']), //逾期暂扣金额
					'FZHSFHJ'=>floatval($v['FZHSFHJ']), //最后实发工资
					'FYHKSXJE'=>floatval($v['FYHKSXJE']), //已回款销售金额
					
					'STJE'=>floatval($v['STJE']),//浮动工资
					'FKYFGZ'=>floatval($v['FKYFGZ']),  //扣已发工资
					'FXJZKK'=>floatval($v['FXJZKK']),  //现金暂扣款 
					'FQJKK'=>floatval($v['FQJKK']),  //请假扣款 
					'FQQJ'=>floatval($v['FQQJ']),  //全勤奖
					'FSDF'=>floatval($v['FSDF']),  //水电费
					'FKK'=>floatval($v['FKK']),  //迟到扣款
					
					'FRemark'=>emptyStrZH($v['FRemark']),  //逾期备注
					'FGRTCFY'=>floatval($v['FGRTCFY']),  //个人提成
					'FDWYB' =>floatval($v['FDWYB']),  //单位医保
					'FKDHF' =>floatval($v['FKDHF']),  //扣电话费
					
			];
		}
	//dd($data);
		//array_column($data, 'FSFHJ');
		if($arr){
			$temp =[];$tempArr =[];
			$temp = SqlServerUtil::exec($this->SqlServer,"SELECT * from t_gzyqkk where  FYear='{$v['FYear']}'  and FPeriod = '{$v['FPeriod']}'");
			if($temp && count($temp)>1){
				//修改操作
				foreach ($temp as $k1=>$v1)
				{
					foreach ($arr as $k2 =>$v2)
					{
						if($v2['FItemID'] == $v1['FItemID']) 
						{
							$tempArr[$k1]['id']=$v1['id'];
							$tempArr[$k1]['FZKBLJE'] =$v2['FSFHJ'] * $v1['FZKBL']/100;
						}
					}
				}
				$update=SqlServerUtil::sqlsrvkqUpdate1($this->SqlServer,'t_gzyqkk',$tempArr);
			}
		}
		
		//存在
		$FItemIDs = join(array_column($data, 'FItemID'), ',');
		SqlServerUtil::exec($this->SqlServer, "delete from t_gzlb where FItemID in ($FItemIDs) and FYear  ='{$v['FYear']}' and FPeriod ='{$v['FPeriod']}'");
		//$qkid=DB::table('t_gzlb')->insert($data);
		$qkid=SqlServerUtil::sqlsrvAll($this->SqlServer,'t_gzlb',$data);
		if($qkid){
			showMsg(200,'保存成功');
		}else{
			showMsg(400,'保存失败');
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function allPicture(Request $request)
	{
		$file = $request->file('file');
		//临时绝对路径
		$realPath = $file->getRealPath();
		//获取 后缀名getClientOriginalExtension
		$ext = $file->getClientOriginalExtension();
		//获取原始文件名getClientOriginalName
		$filename =$file->getClientOriginalName();
		//截取文件名字
		$filerealname = trim(substr($filename,0,strrpos($filename,'.')));
		//getClientMimeType
		//  $url = $_SERVER['HTTP_HOST'].'/uploads/'.$filename;
		$url ='/uploads/'.$filerealname.'.'.$ext;
		$w_filename = $filerealname.'.'.$ext;
		$res = Storage::disk('uploads')->put($w_filename,file_get_contents($realPath));
		
		$getimage = SqlServerUtil::exec($this->SqlServer,"select * from yd_series_pic where item_number = '{$filerealname}'");
		if(count($getimage)>0){
			//存在 删除
			SqlServerUtil::exec($this->SqlServer,"DELETE yd_series_pic WHERE item_number= '{$filerealname}'");
		}
		
		$time =time();
		if($res){
			$data=[
					'item_number'=>$filerealname,
					'url'=>$url,
					'createtime'=>time(),
			];
			
			SqlServerUtil::create($this->SqlServer,'yd_series_pic',$data);
		}
		//     	return response()->json($this->response);
		showMsg('200','成功',$url);
	}
	
	public function delImage(Request $request){
		
		$pragma = $request->all();
		
		$disk = Storage::disk('uploads');
		$url =basename($pragma['url']);
		//     	dd($pragma,$url);
		//获取文件名
		$filename = current(explode('.', $url));
		//删除
		SqlServerUtil::execSql($this->SqlServer,"DELETE yd_goods_pic WHERE item_number= '{$filename}'");
		//dd($filename,$disk,);
		
		// 删除单条文件 $pragma['name']
		$disk->delete($url);
		return response()->json($this->response);
	}
	
	
	public function uploadImage(Request $request){
		$file = $request->file('file');
		//临时绝对路径
		$realPath = $file->getRealPath();
		//获取 后缀名getClientOriginalExtension
		$ext = $file->getClientOriginalExtension();
		//获取原始文件名getClientOriginalName
		$filename =$file->getClientOriginalName();
		//截取文件名字
		$filerealname = trim(substr($filename,0,strrpos($filename,'.')));
		//getClientMimeType
		$urlpath = $_SERVER['HTTP_HOST'].'/uploads/'.$filename;
		$url ='/uploads/'.$filename;
		$time =time();
		$getimage = SqlServerUtil::exec($this->SqlServer,"select * from yd_goods_pic where item_number = '{$filerealname}'");
		if(count($getimage)>0){
			//存在 删除
			SqlServerUtil::exec($this->SqlServer,"DELETE yd_goods_pic WHERE item_number= '{$filerealname}'");
		}
		
		$res = Storage::disk('uploads')->put($filename,file_get_contents($realPath));
		$time =time();
		if($res){
			$data=[
					'item_number'=>$filerealname,
					'url'=>$url,
					'createtime'=>time(),
			];
			$this->response['result'] = $url;
			
			SqlServerUtil::create($this->SqlServer,'yd_goods_pic',$data);
			
		}
		return response()->json($this->response);
	}
	
	
	
	
	
}